package cn.adelyn.base.gateway.adapter;


import cn.adelyn.common.feign.config.FeignInsideAuthConfig;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**  
 * @author chengze
 * @date 2022/10/17
 * @desc 
 */
public class DefaultAuthConfigAdapterImpl implements AuthConfigAdapter, InitializingBean {

	/**
	 * 无需登录权限 unwanted auth 的uri
	 */
	@Value("#{'${adelyn.auth.unanth-uri:}'.empty ? null : '${adelyn.auth.unanth-uri:}'.split(',')}")
	private LinkedList<String> unAuthUriList;

	private String FEIGN_URI = "/**" + FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/**";

	@Override
	public void afterPropertiesSet() {
		if (Objects.isNull(unAuthUriList)) {
			unAuthUriList = new LinkedList<>();
		}
		unAuthUriList.addFirst(FEIGN_URI);
	}

	@Override
	public List<String> filterPathPatterns() {
		return Collections.singletonList("/*");
	}

	@Override
	public List<String> unAuthPatterns() {
		return unAuthUriList;
	}
}
